package com.xinggq.auth.service.controller;

import com.xinggq.auth.api.itf.TokenManagerApi;
import com.xinggq.auth.api.dto.login.AuthSafeUserInfoDTO;
import com.xinggq.auth.service.service.TokenManagerService;
import com.xinggq.common.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 令牌管理控制器
 * 实现TokenManagerApi接口，提供令牌验证服务
 *
 * @author xinggq
 * @since 2024-10-20
 */
@Slf4j
@RestController("/auth/token")
@RequiredArgsConstructor
public class TokenManagerController implements TokenManagerApi {

    private final TokenManagerService tokenManager;

    @Override
    @Operation(summary = "验证令牌并获取用户信息")
    @GetMapping("/validate")
    public CommonResult<AuthSafeUserInfoDTO> validateTokenAndGetUserInfo(String token) {
        log.debug("验证令牌并获取用户信息: {}", token);
        return CommonResult.ok(tokenManager.validateTokenAndGetUserInfo(token));
    }
}